#!/usr/bin/perl

use strict; 
use DBI;
use CGI;
# use TTrakerSite;
use TTraker;

& print_header;
my $dbh;
& initialize_dbi;

my $query = CGI->new;
my $num = $query->param('num');
my $name = $query->param('name');
my $week = $query->param('week');
my $total = $query->param('total');
my $date_str = $query->param('date_str');

my $comm;
# print "$num, $name, $week, $total, $date_str</br>";

my @weekly_detail = ();
my @weekly_totals = (); 

my $weekly_detail = get_weekly_time_detail ($num, $week);

my $weekly_totals = get_weekly_time_totals ($num, $week);

my @week = @$weekly_detail; 

# my ($Hrs,$Reg,$Ot1,$Ot2,$Vac,$Sta,$Sic,$Brv,$Abs,$Loa); 

my ($Hrs,$Reg,$Ot1,$Ot2,$Vac,$Sta,$Sic,$Brv,$Abs,$Loa) = @$weekly_totals; 

#for $i (0..$#jobs ) {
#  	my $cli = $jobs[$i][0];
#   my $elap = $jobs[$i][1];
#}

# print "$num, $name, $week, $total, $date_str </br>";

& print_weekly_employee_hours;

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub print_weekly_employee_hours
{
  print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_sup_confirm_payroll.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  <div id='box5_1'>
  <h3>Employee: $name <br/> Date: $date_str</h3>
  <form onkeypress='return event.keyCode != 13;' autocomplete='off'  name='activity' action='${cgi_ref}trak_04_sup_adjust_weekly_payroll_hrs.pl' method='post'>
  <input type="hidden" name="empName" value='$name'/>
  <input type="hidden" name="empNum" value='$num'/>
  <input type="hidden" name="weekNum" value='$week'/>
  <input type="hidden" name="total" value='$total'/>
  <input type="hidden" name="date_str" value='$date_str'/>
  <table>
     <tr>
      <th>Num</th>
      <th>Date</th>
      <th>Total</th>
		<th>&nbsp&nbsp</th>
		<th>Reg</th>
      <th>1.5x</th>
      <th>2.0x</th>
      <th>Vac</th>
      <th>Sta</th>
      <th>Sick</th>
      <th>Brv</th>
      <th>Abs</th>
      <th>Loa</th>
    </tr>
ENDHEADER

for my $i (0..$#week ) {
	my $hours = $week[$i][0];
	my $reg = $week[$i][1];
	my $ot1 = $week[$i][2];
	my $ot2 = $week[$i][3];
	my $vac = $week[$i][4];
	my $sta = $week[$i][5];
	my $sic = $week[$i][6];
	my $brv = $week[$i][7];
	my $abs = $week[$i][8];
	my $loa = $week[$i][9];
	my $date = $week[$i][10];
	my $num = $week[$i][11];
#	print "$hours, $reg, $ot1, $ot2, $vac, $sta, $sic, $brv, $abs, $loa</br>";
   print <<ENDHEADER;
    <tr>
     <td>$num</td>
     <td>$date</td>
     <td>&nbsp&nbsp&nbsp $hours</td>
     <td>&nbsp&nbsp</td>
     <td><input type='text' size='4' value = $reg name='payroll_data_reg_${date}'/></td>
     <td><input type='text' size='4' value = $ot1 name='payroll_data_ot1_${date}'/></td>
     <td><input type='text' size='4' value = $ot2 name='payroll_data_ot2_${date}'/></td>
     <td><input type='text' size='4' value = $vac name='payroll_data_vac_${date}'/></td>
     <td><input type='text' size='4' value = $sta name='payroll_data_sta_${date}'/></td>
     <td><input type='text' size='4' value = $sic name='payroll_data_sic_${date}'/></td>
     <td><input type='text' size='4' value = $brv name='payroll_data_brv_${date}'/></td>
     <td><input type='text' size='4' value = $abs name='payroll_data_abs_${date}'/></td>
     <td><input type='text' size='4' value = $loa name='payroll_data_loa_${date}'/></td>
     <td><b id="warn">&nbsp&nbsp&nbsp $comm</b></td>
   </tr>
ENDHEADER
}
	print <<ENDHEADER;
   <tr>
     <td>&nbsp</td>
     <td>Totals</td>
     <td>&nbsp&nbsp&nbsp $Hrs</td>
     <td>&nbsp&nbsp</td>
     <td>$Reg</td>
     <td>$Ot1</td>
     <td>$Ot2</td>
     <td>$Vac</td>
     <td>$Sta</td>
     <td>$Sic</td>
     <td>$Brv</td>
     <td>$Abs</td>
     <td>$Loa</td>
	</tr>
	</table>
	<br/>
	<input type='submit' value='Update Payroll Hours'>
 	<br/><br/>
	<a href="JavaScript:window.close()">Close Window</a>
	</form>
 	</body>
 	</html>
ENDHEADER
}




